package cn.tedu.oa_system.base.util;

import cn.tedu.oa_system.pojo.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.util.Map;

import static cn.tedu.oa_system.base.constant.SystemConstant.SESSION_KEY_USER_INFO;

@Component
public class SessionUtil {

    @Autowired
    private HttpSession session;

    public void setValue(Map<String,Object> values){
        values.forEach((k,v) -> session.setAttribute(k,v));
    }

    public void setValue(String key,Object value){
        session.setAttribute(key,value);
    }

    public Object getValue(String key){
        return session.getAttribute(key);
    }

    public UserInfo getUserInfo(){
        return (UserInfo)session.getAttribute(SESSION_KEY_USER_INFO);
    }

    public void setUserInfo(UserInfo userInfo){
        session.setAttribute(SESSION_KEY_USER_INFO,userInfo);
    }

}
